﻿//1.全局变量

//2.初始化界面展示方法
function altermessage_handler() {
    $('#dialog-message').dialog({ title: '修改消息类型' });
    var selected = $('#messageGrid').datagrid('getSelected');
    if (selected) {
       
        $("#Id").val(selected.ID);
        $("#Code").val(selected.CODE);
        $("#Name").val(selected.NAME);
        if (selected.WORKFLAG == "1")
            $("#_WorkFlag").attr("checked", "true");
        else
            $("#_WorkFlag").removeAttr("checked");
        if (selected.DEPTFLAG == "1")
            $("#_DeptFlag").attr("checked", "true");
        else
            $("#_DeptFlag").removeAttr("checked");
        $("#WorkFlag").val(selected.WORKFLAG);
        $("#DeptFlag").val(selected.DEPTFLAG);

        $("#sendgroups").combobox('setValues', eval("[" + selected.SENDGROUP + "]"));
        $("#receivegroups").combobox('setValues', eval("[" + selected.RECEIVEGROUP + "]"));
        
        var str = selected.LIMITTIME;
        var len = str.length;

        $("#LimitTime_Num").val(str.substring(0, len - 1));
        $("#LimitTime_Unit").combobox('setValue', str.substring(len, 1));

        $('#dialog-message').dialog('open');

    }
}

function fn_messageGrid() {
    $('#messageGrid').datagrid({
        fit: true,
        fitColumns: true,
        rownumbers: true,
        singleSelect: true,
        url: '../Controller.aspx?controller=MessageController&method=GetMessageTypeData',
        toolbar: [{
            id: 'btnreload-detail',
            text: '刷新',
            iconCls: 'icon-reload',
            handler: function() {
                $('#messageGrid').datagrid('reload');
            }
        }, {
            id: 'btnadd-detail',
            text: '添加',
            iconCls: 'icon-add',
            handler: function() {
                $('#dialog-message').dialog({ title: '添加消息类型' });
                $('#dialog-message').dialog('open');
                $("#messageform").form('clear');
                //$("#WorkFlag").attr("checked", "true");
                //$("#DeptFlag").attr("checked", "true"); 
                $("#WorkFlag").val(0);
                $("#DeptFlag").val(0);
                $("#Id").val(0);

            }
        }, {
            id: 'btnedit-detail',
            text: '修改',
            iconCls: 'icon-edit',
            handler: function() {
                altermessage_handler();
            }
        }, {
            id: 'btndel-detail',
            text: '删除',
            iconCls: 'icon-remove',
            handler: function() {
                var selected = $('#messageGrid').datagrid('getSelected');
                if (selected) {
                    $.messager.confirm('询问', '是否删除?', function(r) {
                        if (r) {
                            requestAjax('../Controller.aspx?controller=MessageController&method=DeleteMessageType', { Id: selected.ID }, function() {
                                $('#messageGrid').datagrid('reload');
                            });
                        }
                    });
                }
            }
}],
            onDblClickRow: function() {
                altermessage_handler();
            }
        });
    }

    function fn_dialog_message() {
        //新增、修改科室弹出框
        $('#dialog-message').dialog({
            modal: true,
            buttons: [{
                text: '确定',
                iconCls: 'icon-ok',
                handler: function() {
                    FormSubmit($('#messageform'), '../Controller.aspx?controller=MessageController&method=SaveMessageType', function() {
                        $('#dialog-message').dialog('close');
                        $('#messageGrid').datagrid('reload');
                    });
                }
            }, {
                text: '取消',
                handler: function() {
                    $('#dialog-message').dialog('close');
                }
}]
            });

            $('#dialog-message').dialog('close');
        }

        function fn_InitCheckBox() {
            $("#_WorkFlag").click(function() {
                if ($("#_WorkFlag").attr("checked")) {
                    $("#WorkFlag").val(1);
                }
                else {
                    $("#WorkFlag").val(0);
                }
                //alert($("#WorkFlag").val());
            });
            $("#_DeptFlag").click(function() {
                if ($("#_DeptFlag").attr("checked")) {
                    $("#DeptFlag").val(1);
                }
                else {
                    $("#DeptFlag").val(0);
                }
            });
        }
        
    
//3.初始化入口
        $(function() {
            fn_messageGrid();
            fn_dialog_message();
            fn_InitCheckBox();
        });

//4.页面方法
 
  